import { Injectable } from '@angular/core';
import { StateMachineService } from "@farris/command-services";
import { FrameContext } from '@farris/devkit';
import { BefRepository, ResponseInfo } from '@farris/bef';
import { FormMessageService, FormNotifyService, CommandService, FormLoadingService, BeActionService } from '@farris/command-services';
import { EMPTY, of } from 'rxjs';
import { tap, map, switchMap } from 'rxjs/operators';

@Injectable()
export class SbssbxFirstFormFrmControllerService {
  constructor(
    private frameContext: FrameContext,
    private messageService: FormMessageService,
    private beActionService: BeActionService,
    public stateMachineService: StateMachineService,
    public formNotifyService: FormNotifyService,
    private commandService: CommandService,
    public loadingService: FormLoadingService
  ) { }

  /**
   * 故障单编号帮助后事件
   * @remarks 
   * @returns 
   */
  gzdbhLookupPicked(): any {
    const bindingData = this.frameContext.bindingData;
    let gzdbh = this.frameContext.bindingData.getValue(['gzdbh']);
    const repository = this.frameContext.repository as BefRepository<any>;
    const requestInfo = repository.restService.buildRequestInfo();
    const actionUri = 'gzdhelpafter';
    const body = {
      gzdbh: gzdbh,
      requestInfo: requestInfo
    }
    const action$ = this.beActionService.invokeAction(actionUri, 'PUT', null, null, body);
    return action$.pipe(
      tap((responseInfo: ResponseInfo) => {
        console.log(responseInfo);
        const sbbh = responseInfo.returnValue.sbbh;
        const sbmc = responseInfo.returnValue.sbmc;
        const gzny = responseInfo.returnValue.gzny;
        const cq = responseInfo.returnValue.cq;
        const sybm = responseInfo.returnValue.sybm;
        bindingData.setValue(['sbbh'], sbbh, true, true);
        bindingData.setValue(['sbmc'], sbmc, true, true);
        bindingData.setValue(['gzny'], gzny, true, true);
        bindingData.setValue(['cq'], cq, true, true);
        bindingData.setValue(['sybm'], sybm, true, true);
        debugger
      })
    )
  }
}
